package de.zainodis.triplog.ui.task;

import android.content.Context;
import android.os.AsyncTask;

import java.util.List;

import de.zainodis.triplog.data.DiaryEntry;

import static junit.framework.Assert.assertTrue;

/**
 * Created by fzarrai on 10/4/2014.
 */
public class NoteLoader extends AsyncTask<Long, Void, List<DiaryEntry>> {

    private Context context;
    private IAsyncTaskParent<List<DiaryEntry>> parent;

    public NoteLoader(Context context, IAsyncTaskParent<List<DiaryEntry>> parent) {
        super();
        this.context = context;
        this.parent = parent;
    }

    @Override
    protected List<DiaryEntry> doInBackground(Long... params) {
        //Parameters contain the trip id
        long tripId = params[0];
        assertTrue("A trip id must be provided when querying for associated diary entries.", tripId > 0);
        return DiaryEntry.getByTripId(context, tripId);
    }

    @Override
    protected void onPostExecute(List<DiaryEntry> result) {
        super.onPostExecute(result);
        parent.onPostExecute(result);
    }
}
